﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1
{
    public partial class Form1 : Form
    {
        private Bank bank=new Bank();
        private ATM atm;
        public Form1()
        {
            InitializeComponent();
            atm = new ATM(bank);

            atm.BigMoneyFetched += OnBigMoneyFetched;
        }
        // 事件处理方法，显示告警信息
        private void OnBigMoneyFetched(object sender, BigMoneyArgs e)
        {
            // 在界面中显示警告信息
            MessageBox.Show($"警告！账号 {e.AccountNumber} 取走了大笔金额：{e.WithdrawAmount:C}", "大额取款警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string accountNumber = txtAccountNumber.Text;
            decimal initiakBalance = decimal.Parse(txtInitialBalance.Text);
            Account account =new Account(accountNumber, initiakBalance); ;
            bank.addAccount(account);
            MessageBox.Show("账号创建成功");
            txtAccountNumber.Text = "";
            txtInitialBalance.Text = "";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string accountNumber = txtAccountNumber.Text;
            decimal amount = decimal.Parse(txtAmount.Text);
            atm.Withdraw(accountNumber, amount);
        }

        private void txtAccountNumber_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtInitialBalance_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }


    //定义一个事件参数类 保存触发事件时的相关信息
    public class BigMoneyArgs : EventArgs
    {
        public string AccountNumber { get; }
        public decimal WithdrawAmount { get; }

        public BigMoneyArgs(string accountNumber, decimal withdrawAmount)
        {
            AccountNumber = accountNumber;
            WithdrawAmount = withdrawAmount;
        }
    }
}
